#include<stdio.h>
#include<linux/fs.h>
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/init.h>

#define BLOCK_SIZE 1024

unsigned char block[BLOCK_SIZE * BLOCK_SIZE * BLOCK_SIZE];

ssize_t publicfs_read(struct file *, char __user *, size_t, loff_t *)
{
    copy_to_user(block, buffer, length);
}

ssize_t publicfs_write(struct file *, const char __user *buffer, size_t length, loff_t *)
{
    copy_from_user(buffer, block, length);
}

struct file_operations publicfs_inode_fops = {
    .write = publicfs_write,  // echo xxx > xxx.txt
    .read  = publicfs_read,   // cat xxx.txt
};

int publicfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool flags)
{
    struct super_block *sb = dir->sb;
    struct inode *inode    = new_inode(sb);

    inode->i_sb = sb;
    inode->fop  = publicfs_inode_fops;

    // inode->i_private = &publicfs_inode_fops;
}

int publicfs_mkdir (struct inode *,struct dentry *,umode_t)
{

}

int publicfs_rmdir (struct inode *,struct dentry *)
{

}

static struct inode_operations publicfs_inode_ops = {
    .create = publicfs_create, // touch xxx.txt
    .mkdir  = publicfs_mkdir,
	.rmdir  = publicfs_rmdir,
};

int publicfs_fill_super(struct super_block *sb, void *data, int flags)
{
    struct inode *root_inode = new_inode(sb);
    root_inode->i_sb = sb;
    root_inode->i_op = &publicfs_inode_ops;
}

struct dentry *publicfs_mount(struct file_system_type *fs_type, int flags, const char *devname, void *data)
{

    return mount_nodev(fs_type, flags, data, publicfs_fill_super);
}

void publicfs_kill_sb(struct super_block *sb)
{

}

struct file_system_type publicfs_type = {
    .owner   = THIS_MODULE,
    .name    = "publicfs",
    .mount   = publicfs_mount,  // mount
    .kill_sb = publicfs_kill_sb // unmount
};

static int publicfs_init()
{

}

module_init(publicfs_init)